<?php
class db {
	private $host	 =DBHOST;
	private $db_name =DB;
	private $db_user =DBUSER;
	private $db_pass = DBPASS;
	protected $conn;
	protected $result;
    public $query;
	
	public function connect()
	{
		$this->conn=mysql_connect($this->host,$this->db_user,$this->db_pass) or die ("Can't access mysql server !!");
		mysql_query("set names 'utf8'");
		mysql_select_db($this->db_name,$this->conn);
	}
	
	public function close()
	{	if($this->conn)
		{
		@mysql_close($this->conn);
		}
	}
	public function get_id(){
	return mysql_insert_id($this->conn);
	}
	
	public function query($query)
	{	
		if($this->conn)
		{
			$this->result=mysql_query($query);
		}
	$this->query=$query;
	}
	
	public function get_query(){
	return $this->query;
	}
	
	public function num_rows()
	{
		if($this->result)
		{
			return mysql_num_rows($this->result);
		}
	}
	
	public function nonquery($query)
	{
	
		if($this->conn)
		{
			if(mysql_query($query))
			{	
				return true;
			}
			else
			{
				return false;
			}
		}
	}
	public function security($str){
	return mysql_real_escape_string($str);
	}
	public function fetch()
	{
		if($this->result)
		{
			return mysql_fetch_assoc($this->result);
		}
		else
		{
			return false;
		}
	}
	public function fetchOne()
	{
		if($this->result)
		{
			return mysql_fetch_assoc($this->result);
		}
		else
		{
			return false;
		}
	}
	
	public function fetchAll()
	{
		if($this->result)
		{
			while($row=mysql_fetch_assoc($this->result))
			{
				$data[]=$row;
			}
			return $data;
		}
		else
		{
			return false;
		}
	}
	
	
	
}

?>